﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************
'http://code.google.com/apis/gdata/articles/gdata_gadgets.html
Imports System.ComponentModel
Imports System.Text

''' <summary>
''' Code snippet class
''' </summary>
''' <remarks></remarks>
Public Class oAuth
    Implements IObjectName
#Region "Enum"
    Enum EnumMethod
        [Get]
        [Post]
    End Enum
#End Region
#Region "Fields"
    '  <Service name="google">
    '  <Access url="https://www.google.com/accounts/OAuthGetAccessToken" method="GET" /> 
    '  <Request url="https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.blogger.com/feeds/" method="GET" /> 
    '  <Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?
    '                      oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback" /> 
    '</Service>

    Private _ServiceName As String = String.Empty
    Private _Access_Url As String = String.Empty
    Private _Access_Method As EnumMethod = EnumMethod.Get
    Private _Request_Url As String = String.Empty
    Private _Request_Method As EnumMethod = EnumMethod.Get
    Private _Authorization_Url As String = String.Empty
    Private _Authorization_callback As String = String.Empty
    Private _Parent As Widget
#End Region
#Region "Property"
    Protected ReadOnly Property Parent() As Object Implements IObjectName.Parent
        Get
            Return _Parent
        End Get
    End Property
    Public Sub SetParent(ByVal ParentObject As Object) Implements IObjectName.SetParent
        _Parent = ParentObject
    End Sub
    <CategoryAttribute("Misc"), Description("Service Name"), Browsable(True)> _
    Public Property ServiceName() As String
        Get
            Return _ServiceName
        End Get
        Set(ByVal value As String)
            _ServiceName = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Access Url")> _
    Public Property Access_Url() As String
        Get
            Return _Access_Url
        End Get
        Set(ByVal value As String)
            _Access_Url = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Access Method")> _
    Public Property Access_Method() As EnumMethod
        Get
            Return _Access_Method
        End Get
        Set(ByVal value As EnumMethod)
            _Access_Method = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Request Url")> _
    Public Property Request_Url() As String
        Get
            Return _Request_Url
        End Get
        Set(ByVal value As String)
            _Request_Url = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Request Method")> _
    Public Property Request_Method() As EnumMethod
        Get
            Return _Request_Method
        End Get
        Set(ByVal value As EnumMethod)
            _Request_Method = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Authorization Callback")> _
    Public Property Authorization_callback() As String
        Get
            Return _Authorization_callback
        End Get
        Set(ByVal value As String)
            _Authorization_callback = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), Description("Authorization Url")> _
    Public Property Authorization_Url() As String
        Get
            Return _Authorization_Url
        End Get
        Set(ByVal value As String)
            _Authorization_Url = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False)> _
    Public ReadOnly Property ObjectName() As String Implements IObjectName.ObjectName
        Get
            Return Me._ServiceName
        End Get
    End Property
#End Region
#Region "Constructor"
    Public Sub New()

    End Sub
#End Region
#Region "Methods"
    Public Sub SetDirty()
        If Me.Parent IsNot Nothing Then Me.Parent.SetDirty()
    End Sub
    Public Function BuildXml()
        Dim sb As StringBuilder = New StringBuilder
        sb.AppendLine("<oAuth>")
        sb.AppendLine("<Service name=""" & Me.ServiceName & """>")
        sb.AppendLine(" <Access url=""" & Me.Access_Url & """ method=""" & Me.Access_Method.ToString.ToUpper & """ />")
        sb.AppendLine(" <Request url=""" & Me.Request_Url & """ method=""" & Me.Request_Method.ToString.ToUpper & """ />")
        sb.AppendLine("<Authorization url=""" & Me.Authorization_Url & "?oauth_callback=" & Me.Authorization_callback & """ /> ")
        sb.AppendLine("</Service>")
        sb.AppendLine("</oAuth>")
        Return sb.ToString
    End Function
#End Region
End Class

